
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
    #region TagItem Model -(by fangyifeng at 2010-12-05 13:59:18)

    /// <summary>
    /// TagItem object'TagItem'.
    /// </summary>
    public class TagItem : System.IComparable
    {
        #region Member Variables

        protected Guid _id;
        protected DateTime _createDate;
        protected Product _product;
        protected Producttag _producttag;

        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        #endregion

        #region Constructors

        public TagItem() { }

        public TagItem(DateTime createDate, Product product, Producttag producttag)
        {
            this._createDate = createDate;
            this._product = product;
            this._producttag = producttag;
        }

        #endregion

        #region Public Properties

        public virtual Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual DateTime CreateDate
        {
            get { return _createDate; }
            set { _createDate = value; }
        }

        public virtual Product Product
        {
            get { return _product; }
            set { _product = value; }
        }


        public virtual Producttag Producttag
        {
            get { return _producttag; }
            set { _producttag = value; }
        }


        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
        #endregion

        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
            if (!(obj is TagItem))
                throw new InvalidCastException("This object is not of type TagItem");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((TagItem)obj).Id);
                    break;
                case "CreateDate":
                    relativeValue = this.CreateDate.CompareTo(((TagItem)obj).CreateDate);
                    break;
                default:
                    goto case "Id";
            }
            if (TagItem.SortDirection == SortDirection.Ascending)
                relativeValue *= -1;
            return relativeValue;
        }
        #endregion
    }

    #endregion
}
